package com.zbcz.crm

import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import com.zbcz.crm.adapter.AccessoriesQueryAdapter
import com.zbcz.crm.databinding.ActivityAccessoriesQueryBinding
import com.zbcz.crm.util.onSingleClick
import com.zbcz.crm.viewmodel.AccessQueryViewModel

class AccessoriesQueryActivity : BaseActivity() {

    companion object {
        const val PRODUCT_ID = "product_id"
    }

    private lateinit var mBinding: ActivityAccessoriesQueryBinding

    private val mViewModel: AccessQueryViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityAccessoriesQueryBinding.inflate(layoutInflater)
        setContentView(mBinding.root)
        init()
    }

    fun init() {
        mBinding.ivBack.onSingleClick {
            finish()
        }
        mBinding.tvSearch.onSingleClick {
            mViewModel.queryAccessoiesList(mBinding.edAccessoriesQueryInput.text.toString())
        }
        mViewModel.mResult.observe(this) {
            mBinding.mList.adapter = it?.let { it1 -> AccessoriesQueryAdapter(it1) }
            mBinding.emptyGroup.visibility = if (it.isNullOrEmpty()) View.VISIBLE else View.GONE
        }
    }

}

